package com.nf.health.app.sport_recipe.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.sport_recipe.bean.SportHistoryBean;
import com.nf.health.app.utils.DateUtil;

import java.util.List;

/**
 * Created by changpeng on 2017/4/11 0011.
 */

public class SportHistoryAdapter extends RecyclerView.Adapter {



    private Context mContext;
    private List<SportHistoryBean> mBean;

    public SportHistoryAdapter(Context context, List<SportHistoryBean> bean) {
        this.mContext = context;
        this.mBean = bean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sport_history, parent, false);
        return new ContentHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SportHistoryBean bean = mBean.get(position);
        if(bean == null){
            return;
        }
        if (holder instanceof ContentHolder) {
            ContentHolder h = (ContentHolder)holder;
            h.tvTime.setText(DateUtil.date2String(bean.getEndtime(),"yyyy-MM-dd hh:mm:ss"));
        }

    }

    @Override
    public int getItemCount() {
        if(mBean == null){
            return 0;
        }
        return mBean.size();
    }


    class ContentHolder extends RecyclerView.ViewHolder {
        TextView tvTime;
        public ContentHolder(View itemView) {
            super(itemView);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
